/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mytracks;

import gui.MainWindow;
import gui.StartPanel;
import java.io.File;
import java.io.RandomAccessFile;
import java.nio.channels.FileChannel;
import java.nio.channels.FileLock;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.UIManager;

/**
 *
 * @author steffen
 */
public class MyTracks {
    private static FileChannel channel;
    private static FileLock lock;
    private static boolean blocked;
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        
        Main();
    }
    
    public static void Main() {
        try {
            channel = new RandomAccessFile(new File("MainLock.txt"),
                    "rw").getChannel();
            lock = channel.tryLock();
            if (lock == null) {
                blocked = true;
            }
        } catch (Exception e) {
            blocked = true;
        }
        if (!blocked) {
            /* Set the Nimbus look and feel */
            //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
            /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
             * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
             */
            try {
                try {
                    javax.swing.UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
                } catch (ClassNotFoundException ex) {
                    Logger.getLogger(MyTracks.class.getName()).log(Level.SEVERE, null, ex);
                } catch (InstantiationException ex) {
                    Logger.getLogger(MyTracks.class.getName()).log(Level.SEVERE, null, ex);
                } catch (IllegalAccessException ex) {
                    Logger.getLogger(MyTracks.class.getName()).log(Level.SEVERE, null, ex);
                }
            } catch (javax.swing.UnsupportedLookAndFeelException ex) {
                java.util.logging.Logger.getLogger(StartPanel.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            }
            //</editor-fold>

            /* Create and display the form */            
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new MainWindow().setVisible(true);
                }
            });
        }
    }

    protected void exit() {
        try {
            lock.release();// Release the lock
            channel.close();// Close the file
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.exit(0);
    }    
}
